﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace ExpressTreeDemo
{
    /// <summary>
    /// Expression 表达式树，表达式树是将代码表示为可以检查、修改或执行的结构
    /// 表达式树的相关概念
    /// 委托，事件，linq(Language Integrated Query)，lambda
    /// </summary>
    class Program
    {

        static void Main(string[] args)
        {
            //Func<int, int> func = (x) => {
            //    int a = 0;
            //    return x + x;
            //};
            TestClass c = new TestClass(3);
            c.Change2(x=> x+2+2+2);
            c.Print();

            List<int> stringList = new List<int> { 1, 2, 3, 4, 5 };
            var result = from x in stringList where x > 3 select x;
            var result2 = stringList.Where(x => x > 3);

            Console.WriteLine("Hello World!");

            List<School> schools = new List<School>
            {
                new School{ SchoolID = 1, SchoolName="school1", Remark="111"},
                new School{ SchoolID = 2, SchoolName="school2", Remark="222"},
                new School{ SchoolID = 3, SchoolName="school3", Remark="333"},
                new School{ SchoolID = 4, SchoolName="school4", Remark="444"},
                new School{ SchoolID = 5, SchoolName="school5", Remark="555"},
                new School{ SchoolID = 6, SchoolName="school6", Remark="666"},
                new School{ SchoolID = 7, SchoolName="school7", Remark="777"},
                new School{ SchoolID = 8, SchoolName="school8", Remark="888"},
                new School{ SchoolID = 9, SchoolName="school9", Remark="999"},
                new School{ SchoolID = 10, SchoolName="school10", Remark="100"},
            };
            
            var query = schools.AsQueryable()
                .Where(x => x.SchoolID > 5)
                .Where(x => x.SchoolName == "school1")
                .OrderByDescending(x => x.SchoolID).GetSelectListItems(x => x.SchoolName, x => x.SchoolID);
            var testaaa = query.ToList();

            

            var modifywhere = new WhereReplaceModifier<School>(x=>x.SchoolID < 5);
            var newquery = modifywhere.Modify(query.Expression);
            var finalquery = query.Provider.CreateQuery<object>(newquery);
            var test = finalquery.ToList();
            int a = 0;
        }

        static bool Condition(int input)
        {
            return input > 3;
        }

        static int DoChange(int input)
        {
            return input + input;
        }



    }
}
